﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="aadressType_v3", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(AadressTypeV3))]
    public class AadressTypeV3Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IAadressTypeV3 clazz;
        
        public AadressTypeV3Serializer(IAadressTypeV3 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Asukoht!=null) {
                Writer.WriteStartElement("asukoht");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Asukoht))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Ehak!=null) {
                Writer.WriteStartElement("ehak");
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", "x_ehak");
                Writer.WriteString(clazz.Ehak.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Riik!=null) {
                Writer.WriteStartElement("riik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Riik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Postiindeks!=null) {
                Writer.WriteStartElement("postiindeks");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Postiindeks))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AdobId!=null) {
                Writer.WriteStartElement("adob_id");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AdobId))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AdrId!=null) {
                Writer.WriteStartElement("adr_id");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.AdrId))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Tase6!=null) {
                Writer.WriteStartElement("tase6");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase6))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Tase7!=null) {
                Writer.WriteStartElement("tase7");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase7))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Tase8!=null) {
                Writer.WriteStartElement("tase8");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase8))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AdsOid!=null) {
                Writer.WriteStartElement("ads_oid");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AdsOid))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Koodaadress!=null) {
                Writer.WriteStartElement("koodaadress");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Koodaadress))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="asukoht") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType_v3>asukoht");
                }
                clazz.Asukoht = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("asukoht")).Value;
            }
            if (Reader.LocalName=="ehak") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType_v3>ehak");
                }
                clazz.Ehak = new global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.XEhak(Reader.ReadElementString("ehak"));
            }
            if (Reader.LocalName=="riik") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Riik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("riik")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="postiindeks") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType_v3>postiindeks");
                }
                clazz.Postiindeks = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("postiindeks")).Value;
            }
            if (Reader.LocalName=="adob_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType_v3>adob_id");
                }
                clazz.AdobId = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("adob_id")).Value;
            }
            if (Reader.LocalName=="adr_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType_v3>adr_id");
                }
                clazz.AdrId = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("adr_id")).Value;
            }
            if (Reader.LocalName=="tase6") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType_v3>tase6");
                }
                clazz.Tase6 = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase6")).Value;
            }
            if (Reader.LocalName=="tase7") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType_v3>tase7");
                }
                clazz.Tase7 = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase7")).Value;
            }
            if (Reader.LocalName=="tase8") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType_v3>tase8");
                }
                clazz.Tase8 = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase8")).Value;
            }
            if (Reader.LocalName=="ads_oid") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType_v3>ads_oid");
                }
                clazz.AdsOid = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ads_oid")).Value;
            }
            if (Reader.LocalName=="koodaadress") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType_v3>koodaadress");
                }
                clazz.Koodaadress = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("koodaadress")).Value;
            }
        }
    }
}
